package com.laiat.yamba;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.util.Log;

public class NetworkReceiver extends BroadcastReceiver {

	private static final String TAG = NetworkReceiver.class.getSimpleName();

	
	@Override
	public void onReceive(Context context, Intent intent) {
		
		boolean isNetworkDown = intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
		YambaApplication yamba = (YambaApplication)context.getApplicationContext();
		if (isNetworkDown) {
			Log.d(TAG, "onReceive:  NOT connected, cancelling UpdaterService");
			yamba.cancelUpdateAlarm();
		
		} else {
			Log.d(TAG, "onReceive:  connected, scheduling UpdaterService");
			yamba.resetUpdateAlarm();
		}
		
	}

}
